<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="but1">开始</button>
    <button class="but2">停止</button>
    <script>
        var but1 = document.querySelector('.but1');
        var but2 = document.querySelector('.but2');

        var all;
        but1.addEventListener('click', function() {
            all = setInterval(function() {
                console.log(1);
            }, 1)
        })
        but2.addEventListener('click', function() {
            clearInterval(all);
        })
    </script>
</body>

</html>